using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;

public class Cardtranslate : MonoBehaviour
{
    // Start is called before the first frame update
    Vector2 center;
    [SerializeField] float maxtrans = 15f;
    bool istouch = false;
    void Start()
    {
        center = transform.position;
    }

    // Update is called once per frame

    private void Update()
    {
        if (!istouch)
        {
            float xe = Mathf.Sin(Time.time )* maxtrans;
            float ye = Mathf.Cos(Time.time )* maxtrans;
            transform.eulerAngles = new Vector3(ye, -xe, 0);

        }
    }
    private void OnMouseExit()
    {
        istouch = false;
        transform.eulerAngles = new Vector3(0, 0, 0);

    }
    private void OnMouseOver()
    {
        istouch = true;
        Vector2 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        float xder = Mathf.Sin(center.x-mousepos.x)*2f* maxtrans;
        float yder = Mathf.Sin(center.y-mousepos.y)*2f* maxtrans;
        transform.eulerAngles = new Vector3(yder, -xder, 0);

    }
    
}
